package cn.cl.gulimall.product.service.impl;

import cn.cl.gulimall.product.vo.AttrGroupRelationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.cl.common.utils.PageUtils;
import cn.cl.common.utils.Query;

import cn.cl.gulimall.product.dao.AttrAttrgroupRelationDao;
import cn.cl.gulimall.product.entity.AttrAttrgroupRelationEntity;
import cn.cl.gulimall.product.service.AttrAttrgroupRelationService;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		IPage<AttrAttrgroupRelationEntity> page = this.page(
				new Query<AttrAttrgroupRelationEntity>().getPage(params),
				new QueryWrapper<AttrAttrgroupRelationEntity>()
		);

		return new PageUtils(page);
	}

	/**
	 * 保存关联关系
	 *
	 * @param attrGroupRelationVos
	 */
	@Override
	public void saveBatch(List<AttrGroupRelationVo> attrGroupRelationVos) {
		List<AttrAttrgroupRelationEntity> attrAttrgroupRelationEntityList = attrGroupRelationVos.stream().map((item) -> {
			AttrAttrgroupRelationEntity attrAttrgroupRelationEntity = new AttrAttrgroupRelationEntity();
			BeanUtils.copyProperties(item, attrAttrgroupRelationEntity);
			return attrAttrgroupRelationEntity;
		}).collect(Collectors.toList());
		if (attrAttrgroupRelationEntityList != null) {
			this.saveBatch(attrAttrgroupRelationEntityList);
		}
	}
}